/* eslint-disable prettier/prettier */
import { messages } from "share/common";
import { Checkbox, Radio, Select, Form } from "antd";
import moment from "moment";

const CheckboxGroup = Checkbox.Group;
const RadioGroup = Radio.Group;
const Option = Select.Option;
const FormItem = Form.Item;

export default {
  // 差标管控保存时数据解析值
  formatControlData(data, values) {
    let params = Object.assign({}, data);
    let approval = params.travelApprovalControl;
    let standard = params.travelStandardsControl;
    for (const key in values) {
      if (key.includes("_root")) {
        params = Object.assign({}, params, values[key]);
      } else if (key.includes("_approval")) {
        if (typeof values[key] === "object") {
          approval = Object.assign({}, approval, values[key]);
        } else {
          const attrKey = key.substring(0, key.indexOf("_approval"));
          approval[attrKey] = values[key];
        }
      } else if (key.includes("_standard")) {
        if (typeof values[key] === "object") {
          standard = Object.assign({}, standard, values[key]);
        } else {
          const attrKey = key.substring(0, key.indexOf("_standard"));
          standard[attrKey] = values[key];
        }
      } else {        
        params[key] = values[key];
        if (Array.isArray(params[key]) && !key.includes("reason")) {
          //现在含reason理由字段传list
          params[key] = params[key].join(",");
        }
      }
    }
    // params.noControlLowestPricePeriodStart = params.noControlLowestPricePeriodStart.format('HH:mm');// 管控到分钟时格式化
    approval.noApprovalUserGroupId = approval.noApprovalUserGroupId_ === "all" ? "all" : approval.noApprovalUserGroupId;
    params.travelApprovalControl = approval;
    params.travelStandardsControl = standard;
    params.visibleCabinClassUserGroupId =
      params.visibleCabinClassUserGroupId_ === "all" ? "all" : params.visibleCabinClassUserGroupId;
    params.noControlLowestPriceGroupId =
      params.noControlLowestPriceGroupId_ === "all" ? "all" : params.noControlLowestPriceGroupId;
    return params;
  },

  singleCheckboxForm(getFieldDecorator, key, initValue, name, classStyle) {
    return (
      <FormItem className={classStyle}>
        {getFieldDecorator(key, {
          initialValue: initValue || false,
          valuePropName: "checked",
        })(<Checkbox>{name || messages("supplier-1.key35") /* 启用temp*/}</Checkbox>)}
      </FormItem>
    );
  },

  getTimes() {
    const times = [];
    for (let i = 0; i < 24; i++) {
      const hm = i > 9 ? `${i}:00` : `0${i}:00`;
      const time = { time: hm, value: hm };
      times.push(time);
    }
    return times;
  },

  // 差标管控选项组件
  getFormComponent(type) {
    const item = {
      // 可见机票价格选项
      visibleTicketPrice: (
        <RadioGroup>
          <Radio value={1}>{messages("supplier-1.key286") /* 只显示每个舱等最低价*/}</Radio>
          <Radio value={2}>{messages("supplier-1.key287") /* 只显示每个供应商每个舱等下最低价*/}</Radio>
          <Radio value={3}>{messages("supplier-1.key288") /* 不限制*/}</Radio>
        </RadioGroup>
      ),
      // 可见机票类型选项
      visibleTicketType: (
        <CheckboxGroup className="checkbox-margin">
          <Checkbox value="1">{messages("supplier-1.key289") /* 直连票*/}</Checkbox>
          <Checkbox value="2">{messages("supplier-1.key290") /* 航司票*/}</Checkbox>
          <Checkbox value="3">{messages("supplier-1.key291") /* 共享航班*/}</Checkbox>
        </CheckboxGroup>
      ),
      // 最低价管控时间选项
      priceControlTime: (
        <Select style={{ width: 150, marginTop: -6 }}>
          <Option value="1">1{messages("supplier-1.key292") /* 小时*/}</Option>
          <Option value="2">2{messages("supplier-1.key292") /* 小时*/}</Option>
          <Option value="3">3{messages("supplier-1.key292") /* 小时*/}</Option>
          <Option value="4">4{messages("supplier-1.key292") /* 小时*/}</Option>
        </Select>
      ),
      // 最低价管控原因选项
      priceControlReason: (
        <CheckboxGroup className="checkbox-margin">
          <Checkbox value="1">{messages("supplier-1.key293") /* 陪同客户领导*/}</Checkbox>
          <Checkbox value="2">{messages("supplier-1.key294") /* 航空公司偏好*/}</Checkbox>
          <Checkbox value="3">{messages("supplier-1.key295") /* 机场选择*/}</Checkbox>
          <Checkbox value="4">{messages("supplier-1.key296") /* 退改签及行李额因素*/}</Checkbox>
          <Checkbox value="5">{messages("supplier-1.key297") /* 起飞或到达时间不合适*/}</Checkbox>
          <Checkbox value="6">{messages("supplier-1.key298") /* 余票不足*/}</Checkbox>
        </CheckboxGroup>
      ),
      reasonForBeyondStandards: (
        <CheckboxGroup className="checkbox-margin">
          <Checkbox value="1" style={{ marginBottom: 12 }}>
            {messages("supplier-1.key299") /* 领导偏好*/}
          </Checkbox>
          <Checkbox value="2" style={{ marginBottom: 12 }}>
            {messages("supplier-1.key300") /* 陪同客户*/}
          </Checkbox>
          <Checkbox value="3" style={{ marginBottom: 12 }}>
            {messages("supplier-1.key297") /* 起飞或到达时间不合适*/}
          </Checkbox>
          <Checkbox value="4" style={{ marginBottom: 12 }}>
            {messages("supplier-1.key294") /* 航空公司偏好*/}
          </Checkbox>
          <Checkbox value="5" style={{ marginBottom: 12 }}>
            {messages("supplier-1.key301") /* 仅有商务舱以上的舱位*/}
          </Checkbox>
          <Checkbox value="6" style={{ marginBottom: 12 }}>
            {messages("supplier-1.key302") /* 仅有限制折扣以上舱位*/}
          </Checkbox>
          <Checkbox value="7" style={{ marginBottom: 12 }}>
            {messages("supplier-1.key295") /* 机场选择*/}
          </Checkbox>
          <Checkbox value="8" style={{ marginBottom: 12 }}>
            {messages("supplier-1.key303") /* 机型不被接受*/}
          </Checkbox>
          <Checkbox value="9" style={{ marginBottom: 12 }}>
            {messages("supplier-1.key304") /* 航空公司航班周期不被接受*/}
          </Checkbox>
          <Checkbox value="10" style={{ marginBottom: 12 }}>
            {messages("supplier-1.key305") /* 改签或退票因素*/}
          </Checkbox>
          <Checkbox value="11" style={{ marginBottom: 12 }}>
            {messages("supplier-1.key306") /* 航班取消或者延误*/}
          </Checkbox>
          <Checkbox value="12" style={{ marginBottom: 12 }}>
            {messages("supplier-1.key307") /* 原航班取消或延误*/}
          </Checkbox>
        </CheckboxGroup>
      ),
      sameFlightSegmentSortRule: (
        <CheckboxGroup className="checkbox-margin">
          <Checkbox value={10}>{messages("supplier-1.key736") /*按含服务费总价从低到高排序*/}</Checkbox>
          <Checkbox value={20}>{messages("supplier-1.key737") /*按机票票面价从低到高排序*/}</Checkbox>
        </CheckboxGroup>
      ),

      samePriceSortRule: (
        <CheckboxGroup className="checkbox-margin">
          <Checkbox value={10}>{messages("supplier-1.key738") /*随机*/}</Checkbox>
          <Checkbox value={20}>{messages("supplier-1.key739") /*按查询速度优先*/}</Checkbox>
          <Checkbox value={30}>{messages("supplier-1.key740") /*按供应商权重系数优先*/}</Checkbox>
          <Checkbox value={31}>
            {messages("supplier-1.key741") /*按供应商质量权重优先（并隐藏同价其他供应商）*/}
          </Checkbox>
        </CheckboxGroup>
      ),
    };
    return item[type];
  },

  // 差标管控表单组件配置
  getPlaneFormItem(type) {
    const opt = [
      { key: 30, text: messages("supplier-1.key308") /* 强管控*/ },
      { key: 10, text: messages("supplier-1.key309") /* 弱管控*/ },
      { key: 20, text: messages("supplier-1.key310") /* 二次审批*/ },
    ];
    switch (type) {
      case "airClass": // 可见机票舱等
        return {
          checkboxKey: "enabledVisibleCabinClass",
          radioKey: "visibleCabinClassUserGroupId_",
          checkboxOpt: {
            text: messages("supplier-1.key35") /* 启用temp*/,
          },
          radioOpt: [
            { key: "all", text: messages("supplier-1.key128") /* 通用*/ },
            {
              key: "userId",
              text: messages("supplier-1.key311") /* 从人员组选择*/,
            },
          ],
          userGroup: true,
        };
      case "lowPrice":
        return {
          checkboxKey: "controlLowestPrice",
          radioKey: "controlLowestPriceWay",
          checkboxOpt: {
            text: messages("supplier-1.key35") /* 启用temp*/,
          },
          radioOpt: opt,
        };
      case "approval":
        return {
          checkboxKey: "enabledNoApproval",
          radioKey: "noApprovalUserGroupId_",
          checkboxOpt: {
            text: messages("supplier-1.key312") /* 部分员工预订无须审批单*/,
          },
          radioOpt: [
            { key: "all", text: messages("supplier-1.key128") /* 通用*/ },
            {
              key: "userId",
              text: messages("supplier-1.key311") /* 从人员组选择*/,
            },
          ],
          userGroup: true,
        };
      case "date":
        return {
          checkboxKey: "controlDate",
          radioKey: "controlDateWay",
          checkboxOpt: {
            text: messages(
              "supplier-1.key313"
            ) /* 日期控制(1.往返行程会同时校验出发日期与返回日期；2.会兼容审批单中的浮动日期)*/,
          },
          radioOpt: opt,
        };
      case "people":
        return {
          checkboxKey: "controlPassenger",
          radioKey: "controlPassengerWay",
          checkboxOpt: {
            text: messages("supplier-1.key726") /* 乘机人控制(乘机人需要与审批单中参与人一致且同一参与人不能重复订票)*/,
          },
          radioOpt: opt,
        };
      case "address":
        return {
          checkboxKey: "controlSite",
          radioKey: "controlSiteWay",
          checkboxOpt: {
            text: messages(
              "supplier-1.key315"
            ) /* 出发到达地控制(机票出发地与到达地需与审批单一致，支持审批单地点集控制)*/,
          },
          radioOpt: opt,
        };
      case "classLevel":
        return {
          checkboxKey: "controlCabinClass",
          radioKey: "controlCabinClassWay",
          checkboxOpt: {
            text: messages('supplier-1.key771')/*舱等控制*/,
          },
          radioOpt: opt,
        };
      case "discount":
        return {
          checkboxKey: "controlDiscount",
          radioKey: "controlDiscountWay",
          checkboxOpt: {
            text: messages('supplier-1.key772')/*折扣控制*/,
          },
          radioOpt: opt,
        };
      case "advanceBooking":
        return {
          checkboxKey: "controlPreBook",
          radioKey: "controlPreBookWay",
          checkboxOpt: {
            text: messages("supplier-1.key318") /* 提前预定天数*/,
          },
          radioOpt: opt,
        };
      case "amount":
        return {
          checkboxKey: "controlPrice",
          radioKey: "controlPriceWay",
          checkboxOpt: {
            text: messages("common.amount") /* 金额*/,
          },
          radioOpt: opt,
        };
      case "airHourWhiteList": // 前后N小时管控白名单
        return {
          checkboxKey: "enabledNoControlLowestPrice",
          radioKey: "noControlLowestPriceGroupId_",
          checkboxOpt: {
            text: messages("supplier-1.key319") /* 部分员工无需管控*/,
          },
          radioOpt: [
            { key: "all", text: messages("supplier-1.key128") /* 通用*/ },
            {
              key: "userId",
              text: messages("supplier-1.key311") /* 从人员组选择*/,
            },
          ],
          userGroup: true,
        };
      default:break;
    }
  },

  // 退改签选项组件
  getRefundChangeFormComp(type) {
    const option = {
      // 改签方式类型选项
      changeWay: (
        <CheckboxGroup className="checkbox-margin">
          <Checkbox value="0">{messages("supplier-1.key320") /* 因公订单-自愿改签-无需审批*/}</Checkbox>
          <Checkbox value="1">{messages("supplier-1.key321") /* 因公订单-自愿改签-事前审批*/}</Checkbox>
          <Checkbox value="2">{messages("supplier-1.key322") /* 因公订单-自愿改签-事后审批*/}</Checkbox>
          <Checkbox value="4">{messages("supplier-1.key323") /* 因公订单-非自愿改签-无需审批*/}</Checkbox>
          <Checkbox value="5">{messages("supplier-1.key324") /* 因公订单-非自愿改签-事前审批*/}</Checkbox>
          <Checkbox value="6">{messages("supplier-1.key325") /* 因公订单-非自愿改签-事后审批*/}</Checkbox>
        </CheckboxGroup>
      ),
      // 退票方式类型选项
      refundWay: (
        <CheckboxGroup className="checkbox-margin">
          <Checkbox value="0">{messages("supplier-1.key326") /* 因公订单-自愿退票-无需审批*/}</Checkbox>
          <Checkbox value="1">{messages('supplier-1.key932')/*因公订单-自愿退票-事前审批*/}</Checkbox>
          <Checkbox value="2">{messages("supplier-1.key327") /* 因公订单-自愿退票-事后审批*/}</Checkbox>
          <Checkbox value="4">{messages("supplier-1.key328") /* 因公订单-非自愿退票-无需审批*/}</Checkbox>
          <Checkbox value="5">{messages('supplier-1.key933')/*因公订单-非自愿退票-事前审批*/}</Checkbox>
        </CheckboxGroup>
      ),
      // 退票确认方式类型选项
      refundConfirmWay: (
        <CheckboxGroup className="checkbox-margin">
          <Checkbox value="1">{messages("supplier-1.key329") /* 退票时，需员工自行确认费用*/}</Checkbox>
        </CheckboxGroup>
      ),
      change: {
        headKey: "enabledVoluntaryChangeReason",
        contentKey: "voluntaryChangeReasonList",
        optionItem: {
          title: messages("supplier-1.key35") /* 启用temp*/,
          contentItem: [
            { title: messages("supplier-1.key330") /* 个人原因*/, value: "1" },
            {
              title: messages("supplier-1.key331") /* 与客户同航班*/,
              value: "2",
            },
            {
              title: messages("supplier-1.key332") /* 与领导同航班*/,
              value: "3",
            },
            {
              title: messages("supplier-1.key333") /* 领导临时安排*/,
              value: "4",
            },
            {
              title: messages("supplier-1.key334") /* 出差时间临时变更*/,
              value: "5",
            },
          ],
        },
      },
      unChange: {
        // 非自愿改签原因类型选项
        headKey: "enabledInvoluntaryChangeReason",
        contentKey: "involuntaryChangeReasonList",
        optionItem: {
          title: messages("supplier-1.key35") /* 启用temp*/,
          contentItem: [
            { title: messages("supplier-1.key335") /* 天气原因*/, value: "1" },
            { title: messages("supplier-1.key336") /* 网络原因*/, value: "2" },
            { title: messages("supplier-1.key337") /* 系统原因*/, value: "3" },
          ],
        },
      },
      refund: {
        // 自愿退票原因类型选项
        headKey: "enabledVoluntaryRefundReason",
        contentKey: "voluntaryRefundReasonList",
        optionItem: {
          title: messages("supplier-1.key35") /* 启用temp*/,
          contentItem: [
            { title: messages("supplier-1.key330") /* 个人原因*/, value: "1" },
            { title: messages("supplier-1.key338") /* 特殊退票*/, value: "2" },
            {
              title: messages("supplier-1.key333") /* 领导临时安排*/,
              value: "3",
            },
            {
              title: messages("supplier-1.key339") /* 出差目的地变更*/,
              value: "4",
            },
            {
              title: messages("supplier-1.key340") /* 临时取消出差*/,
              value: "5",
            },
          ],
        },
      },
      unRefund: {
        // 非自愿退票原因类型选项
        headKey: "enabledInvoluntaryRefundReason",
        contentKey: "involuntaryRefundReasonList",
        optionItem: {
          title: messages("supplier-1.key35") /* 启用temp*/,
          contentItem: [
            { title: messages("supplier-1.key336") /* 网络原因*/, value: "1" },
            { title: messages("supplier-1.key337") /* 系统原因*/, value: "2" },
            { title: messages("supplier-1.key335") /* 天气原因*/, value: "3" },
            { title: messages("supplier-1.key341") /* 病退原因*/, value: "4" },
            { title: messages("supplier-1.key342") /* 重复购票*/, value: "5" },
          ],
        },
      },
    };
    return option[type];
  },

  // 退改签保存时数据解析
  formatRefundChangeData(data, values) {
    let params = Object.assign({}, data);
    for (const key in values) {
      if (key.includes("_root")) {
        params = Object.assign({}, params, values[key]);
      } else if (key === "activeConfirmRefund") {
        // 新配置退改签用户确认
        params[key] = values[key].includes("1");
      } else {
        params[key] = values[key];
      }
    }
    for (const key in params) {
      if (Array.isArray(params[key]) && !key.includes("Reason")) {
        //现在含reason理由字段传list
        params[key] = params[key].join(",");
      }
    }
    return params;
  },
};
